import { Controller, Post, Body, Get, Param, Req, UseGuards, ParseIntPipe } from '@nestjs/common';
import { OrderService } from './order.service';
import { CreateOrderDto } from './dto/create-order.dto';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '../../common/jwt-auth.guard';

@ApiTags('订单')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('order')
export class OrderController {
  constructor(private readonly orderService: OrderService) {}

  @Post()
  @ApiOperation({ summary: '下单' })
  async create(@Req() req, @Body() dto: CreateOrderDto) {
    return this.orderService.create(req.user, dto);
  }

  @Get()
  @ApiOperation({ summary: '我的订单列表' })
  async findAll(@Req() req) {
    return this.orderService.findAll(req.user);
  }

  @Get(':id')
  @ApiOperation({ summary: '订单详情' })
  async findOne(@Req() req, @Param('id', ParseIntPipe) id: number) {
    return this.orderService.findOne(req.user, id);
  }
}
